{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "bc529fa8",
   "metadata": {},
   "source": [
    "##1.函数的返回值\n",
    ">1.函数一定有返回值（无论是什么编程语言）\n",
    ">2.在其他的编程语言中（如c语言，java等），返回值一定要写，不写会报错！！对于python（更高级的语言），返回值如果不写，给定默认值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3834e60f",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-6-d865c0d59be9>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-6-d865c0d59be9>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    def get_formatted_name(first_name,last_name)\u001b[0m\n\u001b[0m                                                ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "def get_formatted_name(first_name,last_name)\n",
    "    '''返回整洁的姓名'''\n",
    "    full_name = first_name + '' + last_name\n",
    "# print(full_name)\n",
    "# return full_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3a62fad5",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'get_formatted_name' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-4-d28916eb1c7e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mget_formatted_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Li'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'Hua'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'get_formatted_name' is not defined"
     ]
    }
   ],
   "source": [
    "print(get_formatted_name('Li','Hua'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "311f671c",
   "metadata": {},
   "outputs": [],
   "source": [
    "def log_in(username,password):\n",
    "    '''验证登陆信息'''\n",
    "    if username == 'Lihua' and password == 123456:\n",
    "        return 1\n",
    "    else:\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "30b672e1",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'log_in' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-5-ab88a36a2be2>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mlog_in\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Lihua'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m12345\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'log_in' is not defined"
     ]
    }
   ],
   "source": [
    "log_in('Lihua',12345)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85ae7289",
   "metadata": {},
   "source": [
    "## 2.函数的参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "39ed9fd3",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-8-d7a4351c1fd3>, line 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-8-d7a4351c1fd3>\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m    print（request_header）\u001b[0m\n\u001b[0m                        ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "def list_test(request_header):\n",
    "    '''测试输入参数为字典'''\n",
    "    print（request_header）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "655ce585",
   "metadata": {},
   "outputs": [],
   "source": [
    "#https://httpbin.org/get\n",
    "httpbin_get = {\n",
    "  \"args\": {}, \n",
    "  \"headers\": {\n",
    "    \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\", \n",
    "    \"Accept-Encoding\": \"gzip, deflate, br\", \n",
    "    \"Accept-Language\": \"zh-CN,zh;q=0.9\", \n",
    "    \"Host\": \"httpbin.org\", \n",
    "    \"Sec-Fetch-Mode\": \"navigate\", \n",
    "    \"Sec-Fetch-Site\": \"none\", \n",
    "    \"Upgrade-Insecure-Requests\": \"1\", \n",
    "    \"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36\", \n",
    "    \"X-Amzn-Trace-Id\": \"Root=1-61adbb1a-26524826323331142d350bde\"\n",
    "  }, \n",
    "  \"origin\": \"61.242.54.89\", \n",
    "  \"url\": \"https://httpbin.org/get\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "02058d7a",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'dict_test' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-12-de707429c3e9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdict_test\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhttpbin_get\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'headers'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'dict_test' is not defined"
     ]
    }
   ],
   "source": [
    "dict_test(httpbin_get['headers'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df7945bb",
   "metadata": {},
   "source": [
    "##2.函数输出的返回值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6ccd3817",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test1_return():\n",
    "    '''测试返回值return'''\n",
    "    return '你好'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "bf49503d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'你好'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test1_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "fd349d77",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test2_return():\n",
    "    '''测试返回值'''\n",
    "    return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "21c81e19",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test2_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fa361dd1",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test3_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "bc2f4dab",
   "metadata": {},
   "outputs": [],
   "source": [
    "def food_ingred(food,*ingreds):\n",
    "    '''食物配料单'''\n",
    "    return food,ingreds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "0e0476e1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('pizza', ('mushroom', 'green peppers', 'extra cheese'))"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food_ingred('pizza','mushroom','green peppers','extra cheese')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "b4a6a772",
   "metadata": {},
   "outputs": [],
   "source": [
    "# **kwarge\n",
    "def person(stud_name,**stud_info):\n",
    "    '''学生个人信息完善表'''\n",
    "    return stud_name,stud_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "77bd9faa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('Lihua', {'age': 18, 'job': 'student', 'adress': '广州南方学院'})"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "person('Lihua',age=18,job='student',adress='广州南方学院')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "b7bcfa73",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func_name(arg1,arg2,*arg,**kwargs):\n",
    "    '''考虑比较周到的函数参数'''\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "e10ec002",
   "metadata": {},
   "outputs": [],
   "source": [
    "def search4vowels(word):\n",
    "    '''计算文本中出现的元音字母有哪些'''\n",
    "    return set('aeiou') & set(word)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9fb3e65",
   "metadata": {},
   "source": [
    "###3.模块\n",
    "> 1.使用模块可以隐藏函数的源代码\n",
    "> 2.使用的人不需要会底层代码（只需要会使用模块即可）\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "30b2c532",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "c60c243a",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'study' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-29-1124bacabbc6>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mstudy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msearch4vowels\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'holle wenqianya'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'study' is not defined"
     ]
    }
   ],
   "source": [
    "study.search4vowels('holle wenqianya')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "350e3d1a",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(study.news_链接)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
